-module(vernemq_plugin_app).

-behaviour(application).

%% Application callbacks
-export([start/2, stop/1, reload/1,prep_stop/1]).
%% ===================================================================
%% Application callbacks
%% ===================================================================
-define(POOL_DB,db_pool).
-define(POOL_TASK,task_pool).
-define(POOL_APNS,apns_pool).

start(_StartType, _StartArgs) ->
    application:ensure_all_started(worker_pool),
    apns:start(),
    wpool:start_sup_pool(
        ?POOL_DB,
        [
            {workers, 5},%进程池数量
            {worker_type, gen_server},
            {pool_sup_shutdown,5000},
            {worker, {db_worker, []}} %cn_worker_pool:init([InitArg])

        ]
    ),
    wpool:start_sup_pool(
        ?POOL_TASK,
        [
            {workers, 5},%进程池数量
            {worker_type, gen_server},
            {pool_sup_shutdown,5000},
            {worker, {task_worker, []}} %cn_worker_pool:init([InitArg])

        ]
    ),
    wpool:start_sup_pool(
        ?POOL_APNS,
        [
            {overrun_warning,5000},%任务被认为超出（即延迟）的毫秒数,默认值为infinity（即不发出警告）
            {workers, 1},%进程池数量
            {worker_type, gen_server},
            {pool_sup_shutdown,5000},
            {worker, {push_worker_pool, []}} %cn_worker_pool:init([InitArg])
        ]
    ),
    vernemq_plugin_sup:start_link().

stop(_) ->
    error_logger:info_msg("application stop..."),
    ok.

prep_stop(_) ->
    error_logger:info_msg("application prep_stop..."),
    ok.

reload(Module) ->
    code:purge(Module),
    code:load_file(Module),
    error_logger:info_msg("reload module:~p",[Module]).